<template>
  <div>
    <div class="tab" :class="GOINFO === true ? 'goinfo' : ''">
      <div class="tabbg"></div>
    </div>
    <div class="home-box">
      <div class="home-box2">
        <div class="info-box">
          <div class="avatar" @click="goInfo">
            <img src="../assets/images/avatar.jpg" alt="" />
          </div>
          <div class="icon_box">
            <el-tooltip
              class="item"
              effect="dark"
              content="QQ"
              placement="top-start"
            >
              <div class="icon_box_qq" @click="QQClick">
                <img src="../assets/images/QQ.png" alt="" />
              </div>
            </el-tooltip>

            <el-tooltip
              class="item"
              effect="dark"
              content="微信"
              placement="top-start"
            >
              <div class="icon_box_qq" @click="WXClick">
                <img src="../assets/images/微信.png" alt="" />
              </div>
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content="Gitee"
              placement="top-start"
            >
              <div class="icon_box_qq">
                <a href="https://gitee.com/wlmwwww">
                  <img src="../assets/images/Gitee.png" alt="" />
                </a>
              </div>
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content="github"
              placement="top-start"
            >
              <div class="icon_box_qq">
                <a href="https://github.com/wulanmin">
                  <img src="../assets/images/github.png" alt="" />
                </a>
              </div>
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content="友情链接"
              placement="top-start"
            >
              <div class="icon_box_qq" @click="GOlink">
                <img src="../assets/images/link.png" alt="" />
              </div>
            </el-tooltip>
          </div>
          <p class="title" ref="title" id="text">{{ divTyping }}</p>
          <p class="city" v-if="FLAG">登录位置：{{ province }}-{{ city }}</p>

          <p class="date">
            北京时间：{{ dateYear }} {{ dateWeek }} {{ dateDay }}
          </p>
        </div>
        <div class="box">
          <span></span>
          <span></span>
          <span></span>
          <span></span>
          <div class="content">
            <div class="tianqi" v-if="FLAG">
              <div class="tianqi-box">
                <p>友情提示:天气质量({{ air_level }})</p>
                <p>{{ air_tips }}</p>
                <p>当前时间:{{ hours }}</p>
                <p>天气：{{ wea }}</p>
                <p>风向：{{ win }}</p>
              </div>
            </div>
          </div>
        </div>
        <next-page />
      </div>
      <img src="../assets/images/bg.jpg" alt="" class="bj pc" />
      <img src="../assets/images/mobgc.png" alt="" class="bj mo" />
    </div>
    <ng-content class="mobai_none" />
    <!-- 弹窗 -->
    <el-dialog
      title="QQ二维码-奶盖"
      :visible.sync="centerDialogVisibleQQ"
      width="405px"
      center
      class="dialoga"
    >
      <div class="img_box">
        <img src="@/assets/images/QQ.jpg" alt="" />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="centerDialogVisibleQQ = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <el-dialog
      title="微信二维码-奶盖"
      :visible.sync="centerDialogVisibleWX"
      width="420px"
      center
      class="dialoga"
    >
      <div class="img_box">
        <img src="@/assets/images/微信.jpg" alt="" />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="centerDialogVisibleWX = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import NgContent from "../components/NgContent.vue";
import NextPage from "../common/NextPage.vue";
import { ditu } from "../utils/Location";
import { getTianQi } from "../api/tianqi";
import { formatTime } from "../utils/index.js";

export default {
  components: {
    NgContent,
    NextPage,
  },
  data() {
    return {
      titleTest: "风萧萧兮易水寒——奶盖!",
      divTyping: "",
      i: 0,
      city: "",
      province: "",
      FLAG: false,
      GOINFO: false,
      dateDay: null,
      dateYear: null,
      dateWeek: null,
      centerDialogVisibleQQ: false,
      centerDialogVisibleWX: false,
      tianqiform: {
        city: "",
        appid: "64699973",
        appsecret: "rbbY03LG",
        version: "v1",
        unescape: 1,
      },
      air_tips: "",
      air_level: "",
      hours: "",
      wea: "",
      win: "",
    };
  },
  mounted() {
    // window.addEventListener("scroll", this.handleScroll, false);
    // this.divTyping = document.getElementById("text");

    setTimeout(() => {
      this.typing();
    }, 2000);
  },

  created() {
    this.getTianQiAPI();
    this.getLocation();
    this.timeFn();
    setTimeout(() => {
      this.$message.success("Welcome to the milk cover blog ！--奶盖");
    }, 1000);
    // this.GOINGO = false,
  },

  methods: {
    //点击头像
    goInfo() {
      this.GOINFO = true;
      setTimeout(() => {
        this.$router.push("my-info");
      }, 2000);
    },
    //时间
    timeFn() {
      setInterval(() => {
        this.dateDay = formatTime(new Date(), "HH: mm: ss");
        this.dateYear = formatTime(new Date(), "yyyy年MM月dd日");
      }, 1000);
    },
    //获取天气
    getTianQiAPI() {
      //删除字符串最后一个字符
      this.tianqiform.city = this.city.substr(0, this.city.length - 1);
      getTianQi(this.tianqiform)
        .then((res) => {
          console.log(res);
          this.air_tips = res.data[0].air_tips;
          this.air_level = res.data[0].air_level;
          this.hours = res.data[0].hours[0].hours;
          this.wea = res.data[0].hours[0].wea;
          this.win = res.data[0].hours[0].win;
        })
        .catch((error) => {
          console.log(error);
          this.$message.error(`获取天气失败${error}!`);
        });
    },
    //获取位置
    getLocation() {
      let _that = this;
      let geolocation = ditu.initMap("map-container"); //定位
      AMap.event.addListener(geolocation, "complete", (result) => {
        // _that.lat = result.position.lat;
        // _that.lng = result.position.lng;
        _that.province = result.addressComponent.province;
        _that.city = result.addressComponent.city;
        this.FLAG = true;
        // _that.district = result.addressComponent.district;
        console.log(result);
      });
    },

    // str = '用JS实现动态打字效果'
    typing() {
      console.log(this.i);
      if (this.i <= this.titleTest.length) {
        this.divTyping =
          this.divTyping + this.titleTest.slice(this.i - 1, this.i++);
        // this.i++;
        var timer = setTimeout(this.typing, 500);
      } else {
        this.divTyping = this.titleTest;
        console.log(timer);
        clearTimeout(timer);
      }
    },
    // QQ点击
    QQClick() {
      this.centerDialogVisibleQQ = !this.centerDialogVisibleQQ;
    },
    //点击微信
    WXClick() {
      this.centerDialogVisibleWX = !this.centerDialogVisibleWX;
    },
    //友情链接
    GOlink() {
      this.GOINFO = true;
      setTimeout(() => {
        this.$router.push("link");
      }, 2000);
    },
  },
};
</script>

<style lang="less" scoped>
@media screen and (max-width: 750px) {
  .box {
    display: none !important;
  }
  .pc {
    display: none !important;
  }
  .mo {
    display: block !important;
  }
  .mobai_none {
    display: none !important;
  }
  .dialoga /deep/ .el-dialog {
    width: 350px !important;
  }
}
.img_box {
  width: 300px;
  height: 300px;
  img {
    width: 100%;
    height: 100%;
  }
}
.label {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.tab {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 100vh;
  transition: 2s;
  z-index: 999;
  background-color: #fff;
  .tabbg {
    width: 100%;
    height: 100vh;
    background: url(~@/assets/images/bgaa.png) no-repeat;
    background-size: cover;
    background-position: center center;
    opacity: 0.5;
  }
}
.goinfo {
  width: 100%;
}
.home-box {
  position: relative;
  width: 100%;
  height: 100vh;
  // background-image: url(~@/assets/images/bg.jpg);
  // background-size: cover;
  // background-position: center center;
  .bj {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -100;
  }
  .pc {
    display: block;
  }
  .mo {
    display: none;
  }
  .home-box2 {
    position: relative;
    width: 100%;
    height: 100%;
    background: linear-gradient(
      rgba(12, 129, 123, 0.2),
      rgba(255, 129, 151, 0.3)
    );
    .icon_box {
      // display: flex;
      // justify-content: space-between;
      // align-items: center;
      opacity: 0.5;
      .flex();
      width: 100%;
      font-size: 16px;
      color: #ffffff;
      margin: 15px;
      &_qq {
        width: 30px;
        height: 30px;
        padding: 10px;
        cursor: pointer;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
    .info-box {
      position: absolute;
      top: -50%;
      left: 50%;
      width: 500px;
      transition: 2s;
      transform: translate(-50%, -50%);
      animation: myfirst1 2s ease forwards;
      animation-delay: 1s;
      text-align: center;
      @keyframes myfirst1 {
        from {
          top: -50%;
        }
        to {
          top: 50%;
        }
      }
      .avatar {
        width: 100px;
        height: 100px;
        overflow: hidden;
        border: 1px solid @color;
        border-radius: 50%;
        // .label();
        margin: 0 auto;
        cursor: pointer;
        transition: 1s;
        transform: rotate(0);
        img {
          width: 100%;
          height: 100%;
          box-shadow: 0px 0px 30px #ffffff;
        }
        &:hover {
          // animation: rotate 2s;
          transform: rotate(360deg);
        }

        // @keyframes rotate {
        //   from {
        //     transform: rotate(0deg);
        //   }
        //   to {
        //     transform: rotate(360deg);
        //   }
        // }
      }
      .city {
        color: @color;
        font-size: 18px;
      }
      .title {
        // .juzhong();
        font-size: 24px;
        color: @color;
        font-family: STCaiyun;
      }
      .date {
        // .juzhong();
        font-size: 18px;
        color: @color;
      }
    }
    .tianqi {
    }
    // .tianqi-box {
    //   background-color: @color;
    //   border-radius: 10px;
    color: #ffffff;
    //   // line-height: 10px;
    padding: 10px;
    font-size: 18px;
    //   animation: rotate1 3s linear infinite alternate;
    //   box-shadow: 0px 0px 30px @color;
    //   &:hover {
    //     animation: none;
    //   }
    //   @keyframes rotate1 {
    //     from {
    //       opacity: 0.8;
    //     }
    //     to {
    //       opacity: 0.1;
    //     }
    //   }
    // }
  }
}
.box {
  position: absolute;
  top: 200px;
  left: -50%;
  transform: translate(-50%, -50%);
  width: 300px;
  height: 300px;
  background: rgba(255, 128, 171, 0.6);
  box-sizing: border-box;
  overflow: hidden;
  box-shadow: 0 20px 50px rgb(23, 32, 90);
  border: 2px solid rgba(255, 128, 171, 0.6);
  color: white;
  padding: 20px;
  // height: 200px;
  transition: 1s;
  animation: myfirst 1s ease forwards;
  animation-delay: 1s;
  @keyframes myfirst {
    from {
      left: -50%;
    }
    to {
      left: 13%;
    }
  }
}

.box:before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.1);
  transition: 0.5s;
  pointer-events: none;
}

.box:hover:before {
  left: -50%;
  transform: skewX(-5deg);
}

.box .content {
  position: absolute;
  top: 15px;
  left: 15px;
  right: 15px;
  bottom: 15px;
  border: 1px solid #f0a591;
  padding: 20px;
  text-align: center;
  box-shadow: 0 5px 10px rgba(9, 0, 0, 0.5);
}

.box span {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  box-sizing: border-box;
}

.box span:nth-child(1) {
  transform: rotate(0deg);
}

.box span:nth-child(2) {
  transform: rotate(90deg);
}

.box span:nth-child(3) {
  transform: rotate(180deg);
}

.box span:nth-child(4) {
  transform: rotate(270deg);
}

.box span:before {
  content: "";
  position: absolute;
  width: 100%;
  height: 2px;
  background: #50dfdb;
  animation: animate 4s linear infinite;
}

@keyframes animate {
  0% {
    transform: scaleX(0);
    transform-origin: left;
  }
  50% {
    transform: scaleX(1);
    transform-origin: left;
  }
  50.1% {
    transform: scaleX(1);
    transform-origin: right;
  }

  100% {
    transform: scaleX(0);
    transform-origin: right;
  }
}
</style>
